package com.atfusu.controller;

import com.atfusu.base.BaseController;
import com.atfusu.bean.entity.Dict;
import com.atfusu.result.Result;
import com.atfusu.service.DictService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * Title:
 * Author: fusu
 * DateTime:  2022/11/27
 * Description:
 **/
@Controller
@RequestMapping("/dict")
public class DirtController extends BaseController {

    private static final String PAGE_INDEX = "dict/index";

    @DubboReference
    private DictService dictService;

    @RequestMapping
    public String index() {

        return PAGE_INDEX;
    }

    @RequestMapping("/findZnodes")
    @ResponseBody
    public Result findZnodes(@RequestParam(value = "id", defaultValue = "0") Long id) {
        //根据parent_id查找子节点相关信息
        List<Map<String, Object>> znodes = dictService.findZnodes(id);
        //使用result工具类返回数据
        Result<List<Map<String, Object>>> result = Result.ok(znodes);
        return result;
    }


    @RequestMapping("/findListByParentId/{parentId}")
    @ResponseBody
    public Result findListByParentId(@PathVariable Long parentId){

        List<Dict> list = dictService.findListByParentId(parentId);

        return Result.ok(list);
    }


}
